export const sessionStorage = {
    getItem(key: string) {
        let _r: any = window.sessionStorage.getItem(key);
        if (_r && /^\{.*\}$/.test(_r)) _r = JSON.parse(_r);
        return _r;
    },
    setItem(key: string, value: string|object) {
        if (typeof value === typeof {}) value = JSON.stringify(value);
        window.sessionStorage.setItem(key, String(value));
    },
    removeItem(key: any) {
        if (Object.prototype.toString.call(key) === "[object String]") {
            window.sessionStorage.removeItem(key);
            return;
        }
        if (
            Object.prototype.toString.call(key) === "[object Array]" &&
            key.length === 0
        ) {
            window.sessionStorage.removeItem(key[0]);
        } else {
            key.map((index: any) => {
                window.sessionStorage.removeItem(index);
            });
        }
    }
};
export const localStorage = {
    getItem(key: string) {
        let _r: any = window.localStorage.getItem(key);
        if (_r && /^\{.*\}$/.test(_r)) _r = JSON.parse(_r);
        return _r;
    },
    setItem(key: string, value: string|object) {
        if (typeof value === typeof {}) value = JSON.stringify(value);
        window.localStorage.setItem(key, String(value));
    },
    removeItem(key: any) {
        if (Object.prototype.toString.call(key) === "[object String]") {
            window.localStorage.removeItem(key);
            return;
        }
        if (
            Object.prototype.toString.call(key) === "[object Array]" &&
            key.length === 0
        ) {
            window.localStorage.removeItem(key);
        } else {
            key.map((index: any) => {
                window.localStorage.removeItem(index);
            });
        }
    }
};
